package api

import (
	"api-gatwary/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Register(c *gin.Context) {

}

func Upload(c *gin.Context) {
	file, m, err := c.Request.FormFile("image")
	if err != nil {
		return
	}
	//suffix := map[string]bool{
	//	".mp4": true,
	//	".mov": true,
	//	".avi": true,
	//}
	//ext := filepath.Ext(m.Filename)
	//if suffix[ext] == false {
	//	c.JSON(http.StatusOK, gin.H{
	//		"code":    http.StatusOK,
	//		"message": "格式不正确",
	//		"data":    false,
	//	})
	//	return
	//}
	//if m.Size > 2*1024*1024*1024 {
	//	c.JSON(http.StatusOK, gin.H{
	//		"code":    http.StatusOK,
	//		"message": "文件过大",
	//		"data":    false,
	//	})
	//	return
	//}
	upload, err := pkg.Upload(file, m)
	if err != nil {
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "上传成功",
		"data":    upload,
	})
}
